/**
 * Created by apple on 16/9/30.
 */
var type = "";//type=0 我关注的人   type=1：关注我的人(粉丝)
var least_message = "";//系统消息,加载更多
//===================================================================================================================//
//======================================================个人中心======================================================//
//===================================================================================================================//
//个人中心——————个人信息
function center_home_user_info() {
    $.ajax({
        type: 'get',
        url: url_link + 'users/' + user_id,
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_user_info = "";
                if (obj.code == 0) {
                    center_user_info += "<h3 class='small-title'>个人资料</h3>" +
                        "<div class='user-info-box'>" +
                        "<dl class='user-data'>" +
                        "<dt>" +
                        "<em class='headpic'>";
                    if (!obj.data.avatar) {
                        obj.data.avatar = "../../image/base/none.png"
                    }
                    center_user_info += "<img src=" + obj.data.avatar + " style='width: 80px;height: 80px;border-radius: 50%;'></em>";
                    if (obj.data.sex == 1) {
                        center_user_info += "<i class='male-mid'></i>"
                    } else {
                        center_user_info += "<i class='female-mid'></i>"
                    }
                    center_user_info += "</dt>" +
                        "<dd>" +
                        "<h5>" + obj.data.nickname + "<b>LV." + obj.data.level + "</b></h5>" +
                        "<ul>" +
                        "<li style='padding-left: 0;'><em><a href='friend.html' target='_blank'>" + obj.data.follow_count + "</a></em><i>关注</i></li>" +
                        "<span></span>" +
                        "<li><em><a href='fans.html' target='_blank'>" + obj.data.fans_count + "</a></em><i>粉丝</i></li>" +
                        "<span></span>" +
                        "<li><em><a href='thread.html' target='_blank'>" + obj.data.article_count + "</a></em><i>作品</i></li>" +
                        "</ul>" +
                        "</dd>" +
                        "</dl>" +
                        "<div class='user-signature'>" +
                        "<p>" +
                        "<i class='sig-ico-left'></i>" +
                        "<span class='sig'>" + obj.data.sign + "</span>" +
                        "<i class='sig-ico-right'></i>" +
                        "</p>" +
                        "<div class='sig-info'>";
                    if (obj.data.area) {
                        center_user_info += "<span>生日：" + obj.data.birth.substring(0, 10) + "</span>"
                    } else {
                        center_user_info += "<span>生日：保密</span>"
                    }
                    center_user_info += "<em></em><span>注册时间：" + obj.data.createdDate.substring(0, 10) + "</span><em></em>";
                    if (obj.data.area) {
                        center_user_info += "<span>所在地：" + obj.data.area + "</span>"
                    } else {
                        center_user_info += "<span>所在地：保密</span>"
                    }
                    center_user_info += "</div></div></div>" +
                        "<div class='user-jf'>" +
                        "<div class='president'>" +
                        "<ul>";
                    $.each(obj.data.gifttemps, function (i, item) {
                        center_user_info += "<li><i><img src=" + item.pic + " style='width: 80px;height: 80px;'></i><span>" + item.count + " 桶</span></li>"
                    });
                    center_user_info += "</ul>" +
                        "</div>" +
                        "<div class='jf-coins-box'>" +
                        "<div class='jf'>" +
                        "<a href='javascript:;' class='gold-rule'><i>?</i></a>我有金币：<i></i><b class='gold-record'>" + obj.data.gold + "</b>" +
                        "</div>" +
                        "<a href='../recharge.html' class='recharge' target='_blank'>快快充值，多充多送<i></i></a>" +
                        "<div class='coin'>" +
                        "<a href='javascript:;' class='integral-rule'><i>?</i></a>我有积分：<i></i><b class='integral-record'>" + obj.data.integral + "</b>" +
                        "</div>" +
                        "</div>" +
                        "</div>";
                    $('.usercenter-right .user-info').html(center_user_info)
                }
            } catch (e) {

            }
        }
    })
}


//个人中心——————我发布的帖子
function center_home_my_thread() {
    $.ajax({
        type: 'get',
        url: url_link + 'articles',
        async: false,
        data: {
            user_id: user_id,
            page: page,
            rows: 6
        },
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_my_thread = "";
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        //没有我发布的帖子
                        center_my_thread += "<h2 class='none_info' style='margin: 50px 0;'>您还没有发布过任何帖子</h2>"
                    } else {
                        //展示我发布的帖子
                        $.each(obj.data.rows, function (i, item) {
                            center_my_thread += "<li><div class='img-box'><a href='../publish/show.html?article_id=" + item.article_id + "' target='_blank'>";
                            //判断是否是今日更新
                            var updated_time = item.updatedDate.substring(0, 10);
                            if (mytime == updated_time) {
                                center_my_thread += "<span class='create-time' style='letter-spacing: 5px;'>今天</span>"
                            } else {
                                center_my_thread += "<span class='create-time'>" + updated_time + "</span>"
                            }
                            if (item.cover) {
                                center_my_thread += "<img src='" + item.cover + "'>";
                            } else {
                                var _content = item.content.split("$$##MotorTravel##$$");
                                var _count = 0;
                                for (var _a = 0; _a < _content.length; _a++) {
                                    var m = _content[_a].substring(0, 13);
                                    if (m == "$$##Image##$$") {
                                        //有图
                                        _count = 1;
                                        var _content_image_description = _content[_a].split("$$##ImageDescription##$$");
                                        var _content_image_url = _content_image_description[0].split("$$##ImageInfo##$$");
                                        center_my_thread += "<img src=" + _content_image_url[0].substring(13, _content_image_url[0].length) + ">"
                                        break;
                                    }
                                }
                                //纯文字,没有图的情况下,使用备用图片
                                if (_count == 0) {
                                    center_my_thread += "<img src='../../image/base/none_img.png'>"
                                }
                            }


                            center_my_thread += "</a></div>" +
                                "<a href='../publish/show.html?article_id=" + item.article_id + "' target='_blank'>" +
                                "<h5 class='thread-title'>" + item.title + "</h5>" +
                                "</a>" +
                                "<div class='thread-info'>" +
                                "<div class='thread-count'>" +
                                "<span class='click-count'><i></i>" + item.see_count + "</span>" +
                                "<span class='comment-count'><i></i>" + item.comment_count + "</span>" +
                                "<span class='praise-count'><i></i>" + item.gift_count + "</span>" +
                                "</div>" +
                                "<div class='button-area' id='center_home'>" +
                                "<a href='javascript:;' class='usercenter-blue-btn thread-modify-btn' data-article-id=" + item.article_id + ">修改</a>" +
                                "<a href='javascript:;' class='usercenter-red-btn thread-delete-btn' data-article-id=" + item.article_id + ">删除</a>" +
                                "</div>" +
                                "</div>" +
                                "</li>";
                        })
                    }

                    $('.my-thread-list-home').html(center_my_thread)
                }
            } catch (e) {

            }
        }
    })
}


//个人中心——————我发布的帖子——————删除帖子
$(document).on('click', '#center_home .thread-delete-btn', function () {
    var data_article_id = $(this).attr('data-article-id')
    layer.msg('真的要删除该帖子吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            $.ajax({
                type: 'delete',
                url: url_link + 'articles/' + data_article_id,
                async: false,
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        center_home_my_thread();
                    }
                }
            })
        }
    });
});


//个人中心——————我发布的帖子——————编辑文章
$(document).on('click', '#center_home .thread-modify-btn', function () {
    var data_article_id = $(this).attr('data-article-id');
    layer.msg('真的要修改该帖子吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            window.location.href = "../publish/update.html?article_id=" + data_article_id+"&status=1";
        }
    });
});


//===================================================================================================================//
//======================================================好友管理======================================================//
//===================================================================================================================//
//好友管理——————我关注的人 or 关注我的人
function center_friend_my_friend_list() {
    $.ajax({
        type: 'get',
        url: url_link + 'follows',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_list = "";
                total = obj.data.total;
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        //没有我关注的人  or  关注我的人
                        center_list += "<h2 class='none_info' style='margin: 163px 0;'>这里还没有任何人入住</h2>"
                    } else {
                        //展示好友列表
                        $.each(obj.data.rows, function (i, item) {
                            center_list += "<li class='myfriend'>" +
                                "<dl>" +
                                "<dt>" +
                                "<a href='../lookat/article.html?user_id=" + item.user.user_id + "' class='headpic' target='_blank'>" +
                                "<img src=" + item.user.avatar + " style='width: 90px;height: 90px;'/>" +
                                "</a>";
                            if (item.user.sex == 0) {
                                //女生
                                center_list += "<i class='female-mid'></i>"
                            } else {
                                center_list += "<i class='male-mid'></i>"
                            }
                            center_list += "</dt>" +
                                "<dd class='friend-info'>" +
                                "<h5><a href='../lookat/article.html?user_id=" + item.user.user_id + "' target='_blank'>" + item.user.nickname + "<em class='level'>LV." + item.user.level + "</em></a></h5>" +
                                "<ul class='friend-info-count'>" +
                                "<li><span>关注</span> <a href='../lookat/friend.html?user_id=" + item.user.user_id + "' target='_blank'>" + item.user.follow_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li><span>粉丝</span> <a href='../lookat/fans.html?user_id=" + item.user.user_id + "' target='_blank'>" + item.user.fans_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li><span>作品</span> <a href='../lookat/article.html?user_id=" + item.user.user_id + "' target='_blank'>" + item.user.article_count + "</a></li>" +
                                "</ul>" +
                                "<p class='signature'>个性签名：" + item.user.sign + "</p>" +
                                "</dd>" +
                                "<dd class='button-area' id='center_attention'>";
                            if (data_motocycle.type == 0) {
                                //我关注的人
                                center_list += "<a href='javascript:;' class='un-follow-btn' id='pay_attention_button' data-user-id=" + data_motocycle.user_id + " data-target-id=" + item.user.user_id + ">" +
                                    "<i></i>取消关注</a>"
                            } else if (data_motocycle.type == 1 && item.user.has_each_follow == 1) {
                                //相互关注
                                center_list += "<a href='javascript:;' class='un-follow-btn' id='pay_attention_button' data-user-id=" + data_motocycle.user_id + " data-target-id=" + item.user.user_id + "><i></i>取消关注</a>"
                            } else {
                                //对方关注了我,但我没有关注对方
                                center_list += "<a href='javascript:;' class='follow-btn' id='pay_attention_button' data-user-id=" + data_motocycle.user_id + " data-target-id=" + item.user.user_id + ">" +
                                    "<i></i>关注</a>"
                            }
                            center_list += "<a href='javascript:;' class='private-btn' id='private_letter_button'><i></i>发私信</a></dd></dl></li>"
                        })
                    }
                    $('.my-friend-list').html(center_list);
                    $('.small-title-friend a').children('em').text("");
                    $('.small-title .current').children('em').text(obj.data.total + "人");
                }
            } catch (e) {

            }
        }
    })
}


//===================================================================================================================//
//======================================================消息中心======================================================//
//===================================================================================================================//
//消息中心——————评论
function center_commend() {
    $.ajax({
        type: 'get',
        url: url_link + 'comments',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_commend_list = "";
                total = obj.data.total;
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        if (data_motocycle.type == 0) {
                            //没有关于我的评论
                            center_commend_list += "<h2 class='none_info'>您还没有收到过任何评论</h2>"
                        } else {
                            //我没有发出过任何评论
                            center_commend_list += "<h2 class='none_info'>您还没有发出过任何评论</h2>"
                        }

                    } else {
                        //展示好友列表
                        $.each(obj.data.rows, function (i, item) {
                            center_commend_list += "<dl class='comment-list'><dt>"
                            if (item.user.user_id == data_motocycle.user_id) {
                                //本人
                                center_commend_list += "<a href='home.html' target='_blank' class='headpic'>"
                            } else {
                                center_commend_list += "<a href='../lookat/friend.html?user_id=" + item.user.user_id + "' target='_blank' class='headpic'>"
                            }

                            center_commend_list += "<img src=" + item.user.avatar + " style='width:70px;height:70px;'></a>";
                            if (item.user.sex == 1) {
                                center_commend_list += "<b class='male-mid'></b>";
                            } else {
                                center_commend_list += "<b class='female-mid'></b>";
                            }
                            center_commend_list += "</dt><dd style='margin-left: 20px;width:717px'><h5>";
                            if (item.user.user_id == data_motocycle.user_id) {
                                //本人
                                center_commend_list += "<a href='home.html' target='_blank' class='username'>"
                            } else {
                                center_commend_list += "<a href='../lookat/friend.html?user_id=" + item.user.user_id + "' target='_blank' class='username'>"
                            }

                            center_commend_list += item.user.nickname + "</a>";
                            //判断是否是今日更新
                            var created_time = item.createdDate.substring(0, 10);
                            if (mytime == created_time) {
                                item.createdDate = "今天   " + item.createdDate.substring(11, item.createdDate.length)
                            }
                            center_commend_list += "<em>" + item.createdDate + "</em>" +
                                "<div class='button-area comment-operate' id='center_comment'>" +
                                "<a href='javascript:;' class='usercenter-red-btn comment-delete-btn' data-comment-id=" + item.comment_id + " >删除</a>" +
                                "</div>" +
                                "</h5>" +
                                "<div class='comment-content'>" +
                                "<div class='comment-p'>";
                            if (item.article) {
                                //原贴还存在
                                center_commend_list += "<p>" + item.content + "</p>";
                                if (item.pic_url) {
                                    center_commend_list += "<a href='javascript:;' class='comment-imgBox commentImgBox'>" +
                                        "<img src=" + item.pic_url + " style='width:80px;height:80px;'>" +
                                        "</a>"
                                }
                                if (item.comment) {
                                    //有二级评论
                                    center_commend_list += "<div class='quote'>" +
                                        "<div class=quote-box'>" +
                                        "<span class='quote-title' style='color: black;'>" +
                                        "回复了" +
                                        "<a href='home.html' target='_blank' style='padding: 0 5px;color: #2175d0;'>" + item.comment.user.nickname + "</a>" +
                                        "对帖子" +
                                        "<a href='../publish/show.html?article_id=" + item.comment.article.article_id + "' target='_blank' style='padding: 0 5px;color: #2175d0;'>《" + item.article.title + "》</a>的评论：" +
                                        "</span>" +
                                        "<div class='quote-content'>" +
                                        "<p>" + item.comment.content + "</p>";
                                    if (item.comment.pic_url) {
                                        center_commend_list += "<a href='javascript:;' class='comment-imgBox'>" +
                                            "<img src=" + item.comment.pic_url + " style='width:80px;height:80px;'>" +
                                            "</a>"
                                    }
                                    center_commend_list += "</div></div></div>"
                                } else {
                                    //一级评论
                                    center_commend_list += "<div class='quote commentImgBox'>" +
                                        "<div class='quote-box'>" +
                                        "<span  style='color: black;'>评论了帖子: </span>" +
                                        "<a href='../publish/show.html?article_id=" + item.article.article_id + "' target='_blank' style='color: #2175d0;'>《" + item.article.title + "》</a>" +
                                        "</div>" +
                                        "</div>";
                                }
                            } else {
                                center_commend_list += "<p class='comment-deleted'>原贴已被删除</p>"
                            }

                            center_commend_list += "</div></div></dd><div style='clear:both'></div></dl>";
                        })
                    }
                    $('#my_comment').html(center_commend_list);

                }
            } catch (e) {

            }
        }
    })
}


//消息中心——————评论——————"我发出的评论"和"我收到的评论"按钮
$(document).on('click', '.commend_button_choose a', function () {
    $('.commend_button_choose a').removeClass('current');
    $(this).addClass('current');
    $('.pageNum').html('')
    if ($(this).hasClass('receive-commend')) {
        //我收到的评论
        data_motocycle = {
            user_id: user_id,
            page: 1,
            type: 0,
            rows: 10
        };
        center_commend();
        var _pagenum = Math.ceil(total / data_motocycle.rows);
        if (_pagenum > 1) {
            //需要分页展示
            $('.pageNum').show();
            $('.pageNum').createPage({
                pageCount: _pagenum,
                current: data_motocycle.page,
                backFn: function (p) {
                    //单击回调方法，p是当前页码
                    data_motocycle.page = p;
                    center_commend();
                }
            });
        }
    } else {
        data_motocycle = {
            user_id: user_id,
            page: 1,
            type: 1,
            rows: 10
        };

        center_commend();
        var _pagenum = Math.ceil(total / data_motocycle.rows);
        if (_pagenum > 1) {
            //需要分页展示
            $('.pageNum').show();
            $('.pageNum').createPage({
                pageCount: _pagenum,
                current: data_motocycle.page,
                backFn: function (p) {
                    //单击回调方法，p是当前页码
                    data_motocycle.page = p;
                    center_commend();
                }
            });
        }
    }
});


//消息中心——————删除评论
$(document).on('click', '#center_comment .comment-delete-btn', function () {
    var data_comment_id = $(this).attr('data-comment-id');
    var content = "";
    layer.msg('真的要删除该评论吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            $.ajax({
                type: 'delete',
                url: url_link + 'comments/' + data_comment_id,
                async: false,
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        center_commend()
                    }
                }
            })
        }
    });
});


//消息中心——————打赏——————我收到的打赏
function center_gift_receive() {
    $.ajax({
        type: 'get',
        url: url_link + 'gifts/myGiftsForWeb',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_gift_receive_list = "";
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        center_gift_receive_list += "<h2 class='none_info'>您还没有收到过任何打赏</h2>"
                    } else {
                        total = obj.data.total;
                        //展示好友列表
                        $.each(obj.data.rows, function (i, item) {
                            center_gift_receive_list += "<dl class='comment-list'>" +
                                "<dt><a href='../lookat/article.html?user_id=" + item.user.user_id + "' target='_blank'' class='headpic'>" +
                                "<img src=" + item.user.avatar + " style='width: 70px;height: 70px;' >" +
                                "</a>";
                            if (item.user.sex == 1) {
                                center_gift_receive_list += "<b class='male-mid'></b>"
                            } else {
                                center_gift_receive_list += "<b class='female-mid'></b>"
                            }
                            center_gift_receive_list += "</dt><dd style='margin-left: 20px;'>" +
                                "<h5>" +
                                "<a href='../lookat/article.html?user_id=" + item.user.user_id + "' target='_blank' class='username'>" + item.user.nickname + "</a>" +
                                "<em>" + item.createdDate + "</em>" +
                                "</h5>" +
                                "<div class='comment-content'>";

                            if (item.gifttemp_id == 0) {
                                center_gift_receive_list += "<p>给Wo点赞了</p>"
                            } else {
                                center_gift_receive_list += "<p>给Wo打赏了" + item.gifttemp.name + "，花费了" + item.gifttemp.price + "金币</p>"
                            }
                            center_gift_receive_list += "<div class='quote'><div class='quote-box'>";
                            if (item.articleVo) {
                                if (item.gifttemp_id == 0) {
                                    center_gift_receive_list += "点赞了";
                                } else {
                                    center_gift_receive_list += "打赏了"
                                }
                                center_gift_receive_list += "<span>" +
                                    "<a href='home.html' target='_blank' style='padding: 0 10px;color: #2175d0;'>" + item.articleVo.user.nickname + "</a>" +
                                    "</span>" +
                                    "的帖子" +
                                    "<a href='../publish/show.html?article_id=" + item.articleVo.article_id + "' target='_blank' style='padding: 0 10px;color: #2175d0'>《" + item.articleVo.title + "》</a>";
                            } else {
                                center_gift_receive_list += "<p class='comment-deleted'>原贴已被删除</p>"
                            }
                            center_gift_receive_list += "</div></div></div></dd><div style='clear: both'></div></dl>"
                        })
                    }
                    $('#receive_list').html(center_gift_receive_list);
                }
            } catch (e) {

            }
        }
    })
}


//消息中心——————打赏——————我发出的打赏
function center_gift_send() {
    $.ajax({
        type: 'get',
        url: url_link + 'gifts/sendGiftsForWeb',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_gift_send_list = "";
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        center_gift_send_list += "<h2 class='none_info'>您还没有打赏过</h2>"
                    } else {
                        total = obj.data.total;
                        //展示好友列表
                        $.each(obj.data.rows, function (i, item) {
                            center_gift_send_list += "<dl class='comment-list'>" +
                                "<dt><a href='home.html' target='_blank'' class='headpic'>" +
                                "<img src=" + item.user.avatar + " style='width: 70px;height: 70px;' >" +
                                "</a>";
                            if (item.user.sex == 1) {
                                center_gift_send_list += "<b class='male-mid'></b>"
                            } else {
                                center_gift_send_list += "<b class='female-mid'></b>"
                            }
                            center_gift_send_list += "</dt><dd style='margin-left: 20px;'>" +
                                "<h5>" +
                                "<a href='home.html' target='_blank' class='username'>" + item.user.nickname + "</a>" +
                                "<em>" + item.createdDate + "</em>" +
                                "</h5>" +
                                "<div class='comment-content'>";

                            if (item.gifttemp_id == 0) {
                                center_gift_send_list += "<p>给Ta点赞了</p>"
                            } else {
                                center_gift_send_list += "<p>给Ta打赏了" + item.gifttemp.name + "，花费了" + item.gifttemp.price + "金币</p>"
                            }
                            center_gift_send_list += "<div class='quote'><div class='quote-box'>";

                            if (item.articleVo) {
                                if (item.gifttemp_id == 0) {
                                    center_gift_send_list += "点赞了";
                                } else {
                                    center_gift_send_list += "打赏了"
                                }
                                center_gift_send_list += "<span>" +
                                    "<a href='../lookat/article.html?user_id=" + item.articleVo.user_id + "' target='_blank' style='padding: 0 10px;color: #2175d0;'>" + item.articleVo.user.nickname + "</a>" +
                                    "</span>" +
                                    "的帖子" +
                                    "<a href='../publish/show.html?article_id=" + item.articleVo.article_id + "' target='_blank' style='padding: 0 10px;color: #2175d0'>《" + item.articleVo.title + "》</a>"
                            } else {
                                center_gift_send_list += "<p class='comment-deleted'>原贴已被删除</p>"
                            }
                            center_gift_send_list += "</div></div></div></dd><div style='clear: both'></div></dl>"
                        })
                    }
                    $('#send_list').html(center_gift_send_list);

                }
            } catch (e) {

            }
        }
    })
}


//消息中心——————打赏——————礼物列表
function center_gift_list() {
    $.ajax({
        type: 'get',
        url: url_link + 'gifttemps',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var gift_list = "";
                if (obj.code == 0) {
                    //展示好友列表
                    $.each(obj.data, function (i, item) {
                        gift_list += "<li><i><img src=" + item.pic + " style='width: 80px;height: 80px;'></i>" + item.count + " 桶</li>"
                    });

                    $('.comment-list-top ul').html(gift_list);

                }
            } catch (e) {

            }
        }
    })
}


//消息中心——————打赏——————"我收到的打赏"和"我发出的打赏"按钮
$(document).on('click', '.gift_choose_button a', function () {
    $('.gift_choose_button a').removeClass('current');
    $(this).addClass('current');
    $('.pageNum').html('')
    if ($(this).hasClass('receive-gratuityList')) {
        $('#receive-gratuityList').show();
        $('#send-gratuityList').hide();
        center_gift_receive();
        //分页
        var _pagenum = Math.ceil(total / data_motocycle.rows);
        if (_pagenum > 1) {
            //需要分页展示
            $('.pageNum').show();
            $('.pageNum').createPage({
                pageCount: _pagenum,
                current: data_motocycle.page,
                backFn: function (p) {
                    //单击回调方法，p是当前页码
                    data_motocycle.page = p;
                    center_gift_receive();
                }
            });
        }
    } else {
        $('#receive-gratuityList').hide();
        $('#send-gratuityList').show();
        center_gift_send();
        //分页
        var _pagenum = Math.ceil(total / data_motocycle.rows);
        if (_pagenum > 1) {
            //需要分页展示
            $('.pageNum').show();
            $('.pageNum').createPage({
                pageCount: _pagenum,
                current: data_motocycle.page,
                backFn: function (p) {
                    //单击回调方法，p是当前页码
                    data_motocycle.page = p;
                    center_gift_send();
                }
            });
        }
    }
});


//消息中心——————系统消息
function center_systemMsseage_list() {
    $.ajax({
        type: 'get',
        url: url_link + 'messages',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var systemMsseage_list = "";
                if (obj.code == 0) {
                    if (obj.data.length == 0) {
                        if ($('.my-sysinfo dl').length == 0) {
                            systemMsseage_list += "<h2 class='none_info' style='margin: 163px 0;'>系统没有给您发过消息</h2>"
                        } else {
                            layer.msg("没有更多消息啦~", {time: 3000})
                        }
                        $('.systemMessage_add_more').hide();
                    }
                    $.each(obj.data, function (i, item) {
                        if (i == obj.data.length - 1) {
                            //说明是最后一条消息
                            least_message = item.message_id;
                        }
                        systemMsseage_list += "<dl  style='border-bottom: 1px solid #dfdfdf;' >" +
                            "<div class='info' data-message-id='" + item.message_id + "' style='width: 80%;'>" +
                            "<h5 style='color: black;font-size: 12px;'>" + item.createdDate + "</h5>" +
                            "<p style='color: black;font-size: 16px;'>" + item.notice + "<span style='font-size: 8px;color: black'>(点击可查看详情)</span></p>" +
                            "</div>" +
                            "<div style='float: right;margin-top: -65px;'>" +
                            "<a href='javascript:;' class='usercenter-red-btn comment-message-btn' data-message-id='" + item.message_id + "' >删除</a>" +
                            "</div><div style='clear: both'></div>'" +
                            "</dl>"
                    });
                    if ($('.my-sysinfo dl').length == 0) {
                        $('.my-sysinfo').html(systemMsseage_list);
                    } else {
                        $('.my-sysinfo').append(systemMsseage_list);
                    }
                }
            } catch (e) {

            }
        }
    })
}


//消息中心——————系统消息——————详细信息
$(document).on('click', '.my-sysinfo dl .info', function () {
    var _message_id = $(this).attr('data-message-id');
    $.ajax({
        type: 'get',
        url: url_link + 'messages',
        async: false,
        data: {message_id: _message_id},
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    $('.system_message').show();
                    $('.system_message_div_content p').html(obj.data.content)
                    $('.system_message_div_time').html(obj.data.createdDate)

                }
            } catch (e) {

            }
        }
    })
});


//消息中心——————系统消息——————详细信息——————关闭
$(document).on('click', '.system_message', function () {
    $('.system_message').hide();
    $('.system_message_div_content p').html('')
    $('.system_message_div_time').html('')
});


//消息中心——————系统消息——————删除
$(document).on('click', '.comment-message-btn', function () {
    var _message_id = $(this).attr('data-message-id');
    layer.msg('真的要删除该消息吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            $.ajax({
                type: 'DELETE',
                url: url_link + 'messages',
                async: false,
                data: {
                    user_id: user_id,
                    message_id: _message_id
                    //user_id: 2,
                    //message_id: 49
                },
                success: function (data) {
                    try {
                        var obj = JSON.parse(data);
                        if (obj.code == 0) {
                            layer.msg("删除成功!");
                            setTimeout(function () {
                                location.reload();
                            }, 1000)
                        }
                    } catch (e) {

                    }
                }
            })
        }
    });
});


//消息中心——————系统消息——————加载更多
$(document).on('click', '.systemMessage_add_more', function () {
    data_motocycle = {
        user_id: user_id,
        message_id: least_message
    };
    center_systemMsseage_list()
});


//===================================================================================================================//
//======================================================帖子管理======================================================//
//===================================================================================================================//
//帖子管理——————所有帖子
function center_thread_my_thread_list() {
    $.ajax({
        type: 'get',
        url: url_link + 'articles',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var center_my_thread = "";
                total = obj.data.total;
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        //没有我发布的帖子
                        center_my_thread += "<h2 class='none_info' style='margin: 195px 0;'>您还没有发布过任何帖子</h2>"
                    } else {
                        //展示我发布的帖子
                        $.each(obj.data.rows, function (i, item) {
                            center_my_thread += "<li>" +
                                "<div class='img-box'>" +
                                "<a href='../publish/show.html?article_id=" + item.article_id + "'>"
                            var created_time = item.createdDate.substring(0, 10);
                            if (mytime == created_time) {
                                center_my_thread += "<span class='create-time' style='letter-spacing: 5px;'>今天</span>";
                            } else {
                                center_my_thread += "<span class='create-time'>" + item.createdDate.substring(0, 10) + "</span>";
                            }
                            if (item.cover) {
                                center_my_thread += "<img src='" + item.cover + "'>";
                            } else {
                                var _content = item.content.split("$$##MotorTravel##$$");
                                var _count = 0;
                                for (var _a = 0; _a < _content.length; _a++) {
                                    var m = _content[_a].substring(0, 13);
                                    if (m == "$$##Image##$$") {
                                        //有图
                                        _count = 1;
                                        var _content_image_description = _content[_a].split("$$##ImageDescription##$$");
                                        var _content_image_url = _content_image_description[0].split("$$##ImageInfo##$$");
                                        center_my_thread += "<img src=" + _content_image_url[0].substring(13, _content_image_url[0].length) + ">"
                                        break;
                                    }
                                }
                                //纯文字,没有图的情况下,使用备用图片
                                if (_count == 0) {
                                    center_my_thread += "<img src='../../image/base/none_img.png'>"
                                }
                            }

                            center_my_thread += "</a></div>" +
                                "<a href='../publish/show.html?article_id=" + item.article_id + "'>" +
                                "<h5 class='thread-title'>" + item.title + "</h5>" +
                                "</a>" +
                                "<div class='thread-info'>" +
                                "<div class='thread-count'>" +
                                "<span class='click-count'><i></i>" + item.see_count + "</span>" +
                                "<span class='comment-count'><i></i>" + item.comment_count + "</span>" +
                                "<span class='praise-count'><i></i>" + item.gift_count + "</span>" +
                                "</div>" +
                                "<div class='button-area' id='center_thread'>" +
                                "<a href='javascript:;' class='usercenter-blue-btn thread-modify-btn' data-article-id=" + item.article_id + ">修改</a>" +
                                "<a href='javascript:;' class='usercenter-red-btn thread-delete-btn-thread' data-article-id=" + item.article_id + ">删除</a>" +
                                "</div>" +
                                "</div>" +
                                "</li>";
                        })
                    }
                    $('.my-thread-list-thread').html(center_my_thread);
                    $('.small-title-thread em').text("共有" + obj.data.total + "篇");
                }
            } catch (e) {

            }
        }
    })
}


//帖子管理——————选择"所有帖子","精华帖子","被选题收录"
$(document).on('click', '.small-title-thread .filter li', function () {
    //排序以"最新发布"为基础排序
    $('.comment-nav-thread a').css('color', 'black');
    $('.comment-nav-thread a:first').css('color', '#2175d0');
    //赋值
    var _text = $(this).children('a').html();
    $('.current-filter').text(_text);
    $('.small-title-thread a:first').text(_text);
    //画页面
    var _data_id = $(this).attr('data-id');
    if (_data_id == 1) {
        //所有帖子
        data_motocycle = {
            page: 1,
            rows: 12,
            user_id: user_id
        }

    } else if (_data_id == 2) {
        //精华帖子
        data_motocycle = {
            page: 1,
            rows: 12,
            user_id: user_id,
            is_nice: 1
        }
    } else if (_data_id == 3) {
        //被选题收录
        data_motocycle = {
            page: 1,
            rows: 12,
            user_id: user_id,
            is_theme: 1
        }
    }
    center_thread_my_thread_list();
});


//帖子管理——————选择"最新发布","点击最高","评论最多"
$(document).on('click', '.comment-nav-thread a', function () {
    $('.comment-nav-thread a').css('color', 'black');
    $(this).css('color', '#2175d0');
    var _text = $(this).html();
    is_nice = data_motocycle.is_nice;
    is_theme = data_motocycle.is_theme;
    //精华帖子
    if (is_nice) {
        if (_text == "最新发布") {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                is_nice: is_nice
            }
        } else if (_text == "点击最高") {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                is_nice: is_nice,
                mostSee: 1
            }
        } else {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                is_nice: is_nice,
                mostComment: 1
            }
        }
    }
    //被选题收录
    if (is_theme) {
        if (_text == "最新发布") {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                is_theme: is_theme
            }
        } else if (_text == "点击最高") {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                is_theme: is_theme,
                mostSee: 1
            }
        } else {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                is_theme: is_theme,
                mostComment: 1
            }
        }
    }
    //全部帖子
    if (!is_nice && !is_theme) {
        if (_text == "最新发布") {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id
            }
        } else if (_text == "点击最高") {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                mostSee: 1
            }
        } else {
            data_motocycle = {
                page: 1,
                rows: 12,
                user_id: user_id,
                mostComment: 1
            }
        }
    }
    center_thread_my_thread_list();
});


//帖子管理——————删除文章
$(document).on('click', '#center_thread .thread-delete-btn-thread', function () {
    var data_article_id = $(this).attr('data-article-id');
    layer.msg('真的要删除该帖子吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            $.ajax({
                type: 'delete',
                url: url_link + 'articles/' + data_article_id,
                async: false,
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("删除成功!");
                        setTimeout(function () {
                            location.reload()
                        }, 1000)
                    }
                }
            })
        }
    });
});


//帖子管理——————编辑文章
$(document).on('click', '#center_thread .thread-modify-btn', function () {
    var data_article_id = $(this).attr('data-article-id');
    window.location.href = "../publish/update.html?article_id=" + data_article_id+"&status=1"
});


//===================================================================================================================//
//========================================================草稿箱======================================================//
//===================================================================================================================//
//草稿箱——————列表显示
function center_drafts() {
    $.ajax({
        type: 'get',
        url: url_link + 'articles/drafts',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var drafts_list = "";
                if (obj.code == 0) {
                    total = obj.data.total;
                    $.each(obj.data.rows, function (i, item) {
                        drafts_list += "<li data-mototype=" + item.mototype_id + "><a class='img-box'>";
                        if (item.cover) {
                            drafts_list += "<img src='" + item.cover + "' class='upload'>";
                        } else {
                            var _content = item.content.split("$$##MotorTravel##$$");
                            var _count = 0;
                            for (var _a = 0; _a < _content.length; _a++) {
                                var m = _content[_a].substring(0, 13);
                                if (m == "$$##Image##$$") {
                                    //有图
                                    _count = 1;
                                    var _content_image_description = _content[_a].split("$$##ImageDescription##$$");
                                    var _content_image_url = _content_image_description[0].split("$$##ImageInfo##$$");
                                    drafts_list += "<img src='" + _content_image_url[0].substring(13, _content_image_url[0].length) + "' class='upload'>";
                                    break;
                                }
                            }
                            //纯文字,没有图的情况下,使用备用图片
                            if (_count == 0) {
                                drafts_list += "<img src='../../image/base/none_img.png' style='width: 256px;height: 170px;' class='upload'>"
                            }
                        }
                        drafts_list += "</a>" +
                            "<h5 class='thread-title'><a>" + item.title + "</a></h5>" +
                            "<div class='thread-info'>" +
                            "<div class='button-area'>" +
                            "<a class='usercenter-blue-btn edit-drafts' data-article-id=" + item.article_id + ">编辑</a>" +
                            "<a href='javascript:;' class='usercenter-red-btn draft-delete-btn' data-article-id=" + item.article_id + ">删除</a>" +
                            "</div>" +
                            "</div>" +
                            "</li>"
                    });
                    $('.my-thread-list-drafts').html(drafts_list)
                }
            } catch (e) {

            }
        }
    })
}


//草稿箱——————删除
$(document).on('click', '.draft-delete-btn', function () {
    var _article_id = $(this).attr('data-article-id');
    layer.msg('真的要删除该帖子吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            $.ajax({
                type: 'DELETE',
                url: url_link + "articles/" + _article_id,
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("删除成功!");
                        setTimeout(function () {
                            location.reload()
                        }, 1000)
                    }
                }
            })
        }
    });

});


//草稿箱——————编辑文章
$(document).on('click', '.edit-drafts', function () {
    var data_article_id = $(this).attr('data-article-id');
    window.location.href = "../publish/update.html?article_id=" + data_article_id+"&status=0"
});


//===================================================================================================================//
//========================================================黑名单======================================================//
//===================================================================================================================//
//黑名单——————列表显示
function center_blacklists() {
    $.ajax({
        type: 'get',
        url: url_link + 'blacklists',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var blacklists = "";
                total = obj.data.total;
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        blacklists += "<h2 class='none_info' style='margin: 203px 0;'>没有人在您的黑名单</h2>"
                    } else {
                        $.each(obj.data.rows, function (i, item) {
                            blacklists += "<li class='myfriend'><dl><dt>" +
                                "<a class='headpic'>" +
                                "<img src=" + item.user.avatar + " style='width: 90px;height: 90px;'>" +
                                "</a>";
                            if (item.user.sex == 1) {
                                blacklists += "<i class='male-mid'></i>";
                            } else {
                                blacklists += "<i class='female-mid'></i>";
                            }
                            blacklists += "</dt>" +
                                "<dd class='friend-info'>" +
                                "<h5><a>" + item.user.nickname + "<em class='level'>LV." + item.user.level + "</em></a></h5>" +
                                "<ul class='friend-info-count'>" +
                                "<li><span>关注</span><a style='font-size: 20px;padding-left: 5px;'>" + item.user.follow_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li><span>粉丝</span><a style='font-size: 20px;padding-left: 5px;'>" + item.user.fans_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li><span>作品</span><a style='font-size: 20px;padding-left: 5px;'>" + item.user.article_count + "</a></li>" +
                                "</ul>";
                            if (item.user.sign) {
                                blacklists += "<p class='signature'>个性签名：" + item.user.sign + "</p>";
                            } else {
                                blacklists += "<p class='signature'>个性签名：神秘如Ta，什么也不留下</p>";
                            }
                            blacklists += "</dd>" +
                                "<dd class='button-area'>" +
                                "<a href='javascript:;' class='white-button remove-blacklist-btn' data-target=" + item.user.user_id + "><i></i>移出黑名单</a>" +
                                "<a href='javascript:;' class='white-button private-btn message-button' id='private_letter_button'><i></i>发私信</a>" +
                                "</dd></dl></li>";
                        })

                    }
                    $('.myfriend-list ul').html(blacklists)
                }
            } catch (e) {
            }
        }
    })

}


//黑名单——————移除黑名单
$(document).on('click', '.remove-blacklist-btn', function () {
    var m = $(this);
    var _html = m.html();
    _html = _html.substring(7, _html.length);
    if (_html == "拉黑") {
        layer.msg('确定要将Ta加入黑名单中？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.post(url_link + 'blacklists', {
                    user_id: user_id,
                    target_id: m.attr('data-target')
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("加入黑名单成功!", {time: 1000});
                        m.html("<i></i>加入黑名单")
                    }
                })
            }
        });
    } else {
        layer.msg('确定要将Ta从黑名单中移除？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.post(url_link + 'blacklists', {
                    user_id: user_id,
                    target_id: m.attr('data-target')
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("移除黑名单成功!", {time: 1000});
                        m.html("<i></i>拉黑")
                    }
                })
            }
        });
    }
});


//===================================================================================================================//
//======================================================收藏管理======================================================//
//===================================================================================================================//
//收藏管理——————列表显示
function center_articlesaves() {
    $.ajax({
        type: 'get',
        url: url_link + 'articlesaves',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var articlesaves = "";
                total = obj.data.total;
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        $('.small-title-favorite em').html("");
                        articlesaves += "<h2 class='none_info' style='margin: 163px 0;'>这里空空如也</h2>"
                    } else {
                        $.each(obj.data.rows, function (i, item) {
                            articlesaves += "<li>" +
                                "<div class='articles_list_div'>" +
                                "<a href='../discover_theme.html?mototype_id=" + item.mototype_id + "' class='topic-lab' target='_blank' data_mototype_id='" + item.mototype_id + "'>" + item.mototype_name + "</a>" +
                                "<a href='../publish/show.html?article_id=" + item.article_id + "' target='_blank' class='img-box'>";
                            if (item.cover) {
                                articlesaves += "<img src='" + item.cover + "'>";
                            } else {
                                var _content = item.content.split("$$##MotorTravel##$$");
                                var _count = 0;
                                for (var _a = 0; _a < _content.length; _a++) {
                                    var m = _content[_a].substring(0, 13);
                                    if (m == "$$##Image##$$") {
                                        //有图
                                        _count = 1;
                                        var _content_image_description = _content[_a].split("$$##ImageDescription##$$");
                                        var _content_image_url = _content_image_description[0].split("$$##ImageInfo##$$");
                                        articlesaves += "<img src='" + _content_image_url[0].substring(13, _content_image_url[0].length) + "'>"
                                        break;
                                    }
                                }
                                //纯文字,没有图的情况下,使用备用图片
                                if (_count == 0) {
                                    articlesaves += "<img src='../../image/base/none_img.png'>"
                                }
                            }


                            articlesaves += "</a>" +
                                "<h5 class='thread-title'>" +
                                "<a href='../publish/show.html?article_id=" + item.article_id + "' target='_blank'><i class='essence'></i>" + item.title + "</a>" +
                                "</h5></div>" +
                                "<div class='thread-info'>" +
                                "<div class='thread-count'>" +
                                "<span class='click-count'><i></i>" + item.see_count + "</span>" +
                                "<span class='comment-count'><i></i>" + item.comment_count + "</span>" +
                                "<span class='praise-count'><i></i>" + item.gift_count + "</span>" +
                                "</div>" +
                                "<div class='button-area'>" +
                                "<a href='javascript:;' class='usercenter-red-btn has-favorite' data-article=" + item.article_id + ">取消收藏</a>" +
                                "</div></div></li>"
                        });
                        $('.small-title-favorite em').html("共有" + obj.data.total + "篇帖子")
                    }
                    $('.my-thread-list-favorite').html(articlesaves)
                    //主题颜色
                    topicColor();
                }
            } catch (e) {

            }
        }
    });
}


//收藏管理——————取消收藏
$(document).on('click', '.has-favorite', function () {
    var m = $(this);
    var _html = m.html();
    if (_html == "取消收藏") {
        layer.msg('真的要取消收藏该文章吗？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.post(url_link + 'articlesaves', {
                    user_id: user_id,
                    article_id: m.attr('data-article')
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("取消收藏成功!", {time: 1000});
                        m.html('收藏')
                    }
                })
            }
        });
    } else {
        layer.msg('要收藏该文章吗？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.post(url_link + 'articlesaves', {
                    user_id: user_id,
                    article_id: m.attr('data-article')
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("收藏成功!", {time: 1000});
                        m.html('取消收藏')
                    }
                })
            }
        });
    }

});


//===================================================================================================================//
//======================================================我的兑换======================================================//
//===================================================================================================================//
//我的兑换——————商品显示
function center_redemption() {
    $.ajax({
        type: 'get',
        url: url_link + 'exchanges',
        async: false,
        data: data_motocycle,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var redemption_list = "";
                total = obj.data.total;
                if (obj.code == 0) {
                    if (obj.data.total == 0) {
                        redemption_list += "<h2 class='none_info' style='margin: 163px 0;'>还没有商品上架哦</h2>"
                    } else {
                        $.each(obj.data.rows, function (i, item) {
                            redemption_list += " <div class='cartData'>" +
                                "<div class='data-pic'>" +
                                "<a target='view_window' href='../redemption/redemption_details.html?good_id=" + item.good_id + "'>" +
                                "<img  src=" + item.cover + ">" +
                                "</a>" +
                                "</div>" +
                                "<div class='dataRight'>" +
                                "<div class='dataTop'>" +
                                "<a target='view_window' href='../redemption/redemption_details.html?good_id=" + item.good_id + "' class='productName'>" +
                                "<div class='name'>" + item.good_name + "</div>" +
                                "</a>" +
                                "<div class='price'>" + item.price + "</div>" +
                                "<div class='productNo'>" + item.count + "</div>" +
                                "<div class='last'>" + item.total_price + "</div>" +
                                "</div>" +
                                "</div>" +
                                "</div>"
                        });
                    }
                    $('.good_list').html(redemption_list)
                }
            } catch (e) {

            }
        }
    });
}


//我的金币数量
function gold() {
    $.ajax({
        type: 'get',
        url: url_link + 'users/' + user_id,
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                $('#topBar .coin-count').html(obj.data.gold)
            } catch (e) {

            }
        }
    });
}